﻿var mobile="";
$(function(){
 
    if(sessionStorage.getItem("isgroup")=="0"){
     
     // $("#add").hide();
      //  $("#fs").hide();
        //
     // $("#delsb").hide();
    }
    if(sessionStorage.getItem("type")=="3"){
        $("#fs").hide();
    }
    $("#add").click(function(z){
       // $("#user_name").attr("disabled",false);
       // $("#myModal").find("span").empty();      $("#myModal").find("input").val("");
       // $("#myModalLabel").text("新增");
        //mobile="";
     
      console.log(123);
       parent.addTabs({id:'101',title: '添加节目',close: true,url: '?#/page/Program/addtow'})
    // location.href="?#/page/Program/add";
  
    });
    //appvm.prompt();
   // domain.jsonthis.modify();

//    if(==){
//     $("#fs").html("提交");
//    }else{
//     $("#fs").html("");
//    }
    });


$(document).ready(function () {
$.jgrid.defaults.styleUI = "Bootstrap";
$("#table_list_1").jqGrid({
    data: [],
    datatype: "local",
    height: "100%",
    autowidth: true,
    shrinkToFit: true,
    rowNum: 20,
    rowList: [10, 20, 30,60,90,100,200,500],
    //colNames: ["编号", "名称", "手机号码"],
    colModel: [ {
        name: 'programid', index: 'programid', align:"center",width: 25, label:  domain.language.$t('jiemu_bianhao'), align: 'center',
    },
    {
        name: 'company_id', index: 'company_id', align:"center",width: 25, label: "company_id", align: 'center',hidden:true,
       
 
    },
    
    {
        name: 'group_programid', index: 'group_programid',align:"center", width: 18, label:  domain.language.$t('jiemu_jiemuhao'), align: 'center',
        formatter: function (value, options, row) {
       
            return parseInt(value)+1;
        }
    },
    {
        name: 'festivalname', index: 'festivalname',align:"center", width: 34, label:  domain.language.$t('admin.jiemu_jiemumingcheng'), align: 'center',
    },
    {
        name: 'type', index: 'type',align:"center", width: 23, label: domain.language.$t('admin.jiemu_jiemuleixing'), align: 'center',

        formatter: function (value, options, row) {
                          
            return domain.language.$t('jiemu_jmlx'+value);

        }

    },
    {
        name: 'devicetype', index: 'devicetype',align:"center", width: 18, label:  domain.language.$t('jiemu_shebieleixing'), align: 'center',
        formatter: function (value, options, row) {
            return domain.language.$t('jiemu_sblx'+value);

        }
    },
 
    {
        name: 'starttime', index: 'starttime',align:"center", width: 25, label: domain.language.$t('jiemu_bfkssj'), align: 'center',
        formatter: function (value, options, row) {
           
            if(typeof(value)!="undefined"){
                try{
             var date = new Date(value)
                
             return date.Format("yyyy-MM-dd");
                }catch(ex){
 
                 console.log(ex);
                }
            }
            return "";
         }
    },
    {
        name: 'endtime', index: 'endtime',align:"center", width: 25, label: domain.language.$t('jiemu_bfjssj'), align: 'center',
        formatter: function (value, options, row) {
           
            if(typeof(value)!="undefined"){
                try{
             var date = new Date(value)
                
             return date.Format("yyyy-MM-dd");
                }catch(ex){
 
                 console.log(ex);
                }
            }
            return "";
         }
    },
   // {
     //   name: 'order_serialno', index: 'order_serialno',align:"center", width: 30, label: "订单号", align: 'center',
   // },
    {
        name: 'zeroindex', index: 'zeroindex',align:"center", width: 18, label: domain.language.$t('jiemu_fqsl'), align: 'center',
    },
    {
        name: 'create_time', index: 'create_time', align:"center",width: 38, label: domain.language.$t('jiemu_shijian'), align: 'center',
        formatter: function (value, options, row) {
           
           if(typeof(value)!="undefined"){
               try{
            var date = new Date(value)
               
            return date.Format("yyyy-MM-dd hh:mm:ss");
               }catch(ex){

                console.log(ex);
               }
           }
           return "";
        },
    },
   
    {
        name: 'permissions', index: 'permissions', width: 20,align:"center", label:  domain.language.$t('jiemu_shenghezhuangtai'), align: 'center',
        formatter: function (value, options, row) {
      //console.log(options.rowId);
      var html = "";
      if(parseInt(value)==1){
        html = "<a style='color:green' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('"+options.rowId+"')>"+domain.language.$t('jiemu_shzt1')+"</a>";
      }
      if(parseInt(value)==2){
        html = "<a style='color:blue' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('"+options.rowId+"')>"+domain.language.$t('jiemu_shzt2')+"</a>";
      }
      if(parseInt(value)==3){
        html = "<a style='color:red' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('"+options.rowId+"')>"+domain.language.$t('jiemu_shzt3')+"</a>";
      }if(parseInt(value)==4){
        html = "<a style='color:red' data-target='#modalExamine'  data-toggle='modal' onclick=queryExamine('"+options.rowId+"')>"+domain.language.$t('jiemu_shzt4')+"</a>";
      }
      return html;
        }
    },
    {
        name: 'user_id', index: 'user_id',align:"center", width: 20, label: "", align: 'center',hidden:true,

    },
    {
        name: 'user_name', index: 'user_name',align:"center", width: 20, label: domain.language.$t('jiemu_chuangjianzhe'), align: 'center',
    },
   
    {
        name: 'xq', index: 'xq', width: 25,align:"center", label: domain.language.$t('jiemu_shenghezhuangtai'), align: 'center',
        formatter: function (value, options, row) {
    
          var html = "<button type='button'  class='btn btn-primary' onclick=modify('"+row.programid+"','"+row.group_programid+"');>"+domain.language.$t('jiemu_chaknjiemu')+"</button>";
        
          return html;
        }
    },
],
    pager: "#pager_list_1",
    viewrecords: true,
    multiselect:true,
    caption: domain.language.$t('jiemu_jiemuliebiao'),
    hidegrid: false,
    ondblClickRow:function(row){
    // $("#update").click();
    // modify(row);
      // $('#myModal').modal('show')
    },
 
    onPaging:function(pageBtn){
        console.log(":"+pageBtn); 
//	    	var re_records = $jqgrid.getGridParam('records');//获取返回的记录数  
        var re_page =  $("#table_list_1").getGridParam('page');//获取返回的当前页
        var re_rowNum=  $("#table_list_1").getGridParam('rowNum');//获取每页数
        var re_total=  $("#table_list_1").getGridParam('lastpage');//获取总页数
        //alert(re_total);
        
        if(pageBtn==="next"){
           // initJqgrid(re_page+1,re_rowNum);
          // if()
           pageval=pageval+1;
           cxlist();
        }
        if(pageBtn==="prev"){
            
            pageval=pageval-1;  cxlist();
        }

        if(pageBtn=="last"){
  
            pageval=re_total;
          
            cxlist();

        }
        if(pageBtn=="first"){
  
            pageval=1;
          
            cxlist();

        }
        
        if(pageBtn=="records"){

            sizeval=$(".ui-pg-selbox").val();
            pageval=1;
            cxlist();
        }
    },

});


 $(window).resize(function(){
    $("#table_list_1").setGridWidth($(window).width());
    $("#table_list_1").setGridHeight($(window).height() - 300);});
});
var sizeval=20;
var pageval=1;
var usernameval=$("#usnameval").val();
var conameval="";
var json="";



window.cxlist=function(){
   
    domain.ajaxUrl({
        method: 'POST',
        url: domain.testUrl+"/Threeinjection/programManagement/queryProgramInfoAuditlist",
        data: {size:sizeval,page:pageval,coid:sessionStorage.getItem("coid"),sessionid:sessionStorage.getItem("sid")
        ,festivalname: $("#usnameval").val(), type: $("#type").val(), devicetype: $("#devicetype").val()},
       // datatype:"JSON",
        success: function (response) {

        //    console.log(response);
             
            json=response;
            var data=JSON.parse(response);
            var reader = {
                root: function (obj) { return data.rows; },
                page: function (obj) { return pageval; },
                total: function (obj) { return data.taotal; },
                records: function (obj) {

                    
                    return data.records;
                },
            };
            $("#table_list_1").setGridParam({ data: data.rows, localReader: reader }).trigger('reloadGrid');
            
            var re_records = $("#table_list_1").getGridParam('records');
            if(re_records==0||re_records==null){
                if($(".norecords").html() == null){$("#usnameval").val("");
                    // $("#table_list_1").parent().append("<div class=\"norecords\">没有符合数据</div>");
                    $("#table_list_1").parent().append("<div class=\"norecords\">"+domain.language.$t('jiemu_meiyoufuheshuju')+"</div>");
                }
                $(".norecords").show();
            }else{

                $(".norecords").hide();
            }
            //隐藏修改
            if(sessionStorage.getItem("isgroup")=="0"){
            $("#table_list_1").hideCol("xq");
            $("#table_list_1").setGridWidth($(window).width());
            }

           if(sessionStorage.getItem("isParent")!="true"){
           $(".ui-row-ltr").each(function(){
             if($(this).find("td").eq(2).text()!==sessionStorage.getItem("coid")){
                $(this).hide();
             }
           });
        }
        $("#table_list_1").setGridHeight($(window).height() - 300);
            $("#table_list_1").setGridWidth($(window).width() - 3);
        }
    });
}

//加载审核内容
window.queryExamine=function(i){

    $("#result").val(1);
    $("#reason").val("");
    i = i - 1;
    var jsonval = JSON.parse(json);
    console.log(jsonval.rows[i]); 
    $("#numberNo").val(jsonval.rows[i].programid);
    $("#programNo").val(parseInt(jsonval.rows[i].group_programid)+1);
    $("#programeName").val(jsonval.rows[i].festivalname);
    $("#createId").val(jsonval.rows[i].user_id);
    $("#submitMan").val(jsonval.rows[i].user_name);
    $("#examineMan").val(jsonval.rows[i].auditorName);
    
};

$(function(){
    var programidval="";
  if(sessionStorage.getItem("isgroup")=="1"){

    $("label").eq(2).hide();$("#devicetype").hide();
  }
  
  //按条件查询
    $("button").eq(0).click(function(){
        
         cxlist();
    });
    cxlist();
 





//修改审核状态
$("#updateExamine").click(function(){
    if($("#reason").val()==""){
        swal("OMG!",domain.language.$t('jiemu_yybnwk'), "error");
        return false;
    }
           $.ajax({
               type: "post",
               url: domain.testUrl + "/Threeinjection/programManagement/insertAuditorInfo",
               dataType: "text",
               timeout: 5000,//超时设置
               data: {
                   "sessionid": sessionStorage.getItem("sid"),"companyId":$("#company_id").val(),"programId":$("#numberNo").val(),
                   "programNum":$("#programNo").val(),"programName":$("#programeName").val(),"creatorId":$("#createId").val(),"creatorName":$("#submitMan").val(),"auditorId":sessionStorage.getItem("userId"),
                   "auditorName":sessionStorage.getItem("username"),"resultId":$("#result").val(),"cause":$("#reason").val()
               },

               success: function (data) {
                   
                   data = JSON.parse(data);
                   if (data != "") {
                       if (data.status == "error") {
                           swal("OMG!", domain.language.$t('jiemu_xiugaishibai'), "error");
                       } else {
                           swal("success!", domain.language.$t('jiemu_xiugaichenggong'), "success");
                           $("#updateExamine").prev().click();
                           $("#usnameval").val("");
                           $("#type").val("");
                           $("#devicetype").val("");
                            $("button").eq(0).click();
                            
                            setTimeout(function(){
                            
                            parent.Addtabs.add({ 'id': 15,title:domain.language.$t('jiemu_jiemuleibiao'), 'url': "?#/page/Program/list" });
                            
                        },1000)
                   }

                   } else {
                       swal("OMG!", domain.language.$t('jiemu_xiugaishibai'), "error");

                   }

               }
           });
     
   });
});

 Date.prototype.Format = function(fmt)   
{ 
//author:wangweizhen
  var o = {   
    "M+" : this.getMonth()+1,                 //月份   
    "d+" : this.getDate(),                    //日
    "h+" : this.getHours(),                   //小时   
    "m+" : this.getMinutes(),                 //分   
    "s+" : this.getSeconds(),                 //秒   
    "q+" : Math.floor((this.getMonth()+3)/3), //季度   
    "S"  : this.getMilliseconds()             //毫秒   
  };   
  if(/(y+)/.test(fmt))   
    fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));   
  for(var k in o)   
    if(new RegExp("("+ k +")").test(fmt))   
  fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));   
  return fmt;   
}

//修改跳转
window.modify=function(programid,group_programid){
    // if(sessionStorage.getItem("isgroup")=="0"){
    //     swal("OMG!","请选择卡组","error");
    //     return false;
    // }
//$("#static").val("1");
sessionStorage.setItem("programid",programid);
sessionStorage.setItem("group_programid",parseInt(group_programid)+1);


parent.addTabs({id:'100',title: domain.language.$t('jiemu_xiugaijiajiemu'),close: true,url:'?#/page/Program/edit'});

setTimeout(function(){

 var id=parent.$("#tabSuperior").find(".active").find("a").attr("href");
 var id2=id.split('_');

  //  alert(parent.$("#if"+parent.$("#tabSuperior").find(".active").find("a").attr("href")).html());
//$("#if"+parent.$("#tabSuperior").find(".active").find("a").attr("href")).reload();
//parent.id="tab_100";
//parent.closeTab("tab_100");

parent.Addtabs.add({ 'id': id2[1], 'url':parent.$(id).children("iframe").attr("src") });


//parent.$("#tab_tab_100").find("a").find(".glyphicon-remove").click();
//parent.$("#iftab_100").attr("src","?#/page/Program/edit");



}, 500);
//parent.addTabs({id:'100',title: '修改节目',close: true,url: '?#/page/Program/edit'});
 // domain.jsonthis.userinfo=[json.rows[i].user_name];
    
};






